package com.sirdc.modules.sys.web.Accraditation;

import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.Project.entity.NodeFile;
import net.huashitong.Project.entity.NodeNewfile;
import net.huashitong.Project.service.NodeFileService;
import net.huashitong.Project.service.NodeNewFilterService;
import net.huashitong.node.entity.NodeNewtemplet;
import net.huashitong.node.filter.NodeNewschedulesFilter;
import net.huashitong.node.filter.NodeNewtempletFilter;
import net.huashitong.node.service.NodeNewschedulesService;
import net.huashitong.node.service.NodeNewtempletService;
import net.huashitong.oversee.filter.CoordinateFilter;
import net.huashitong.oversee.filter.SupervisionTaskFilter;
import net.huashitong.oversee.service.CoordinateService;
import net.huashitong.oversee.service.SupervisionTaskService;
import net.huashitong.user.entity.BnpUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.util.WebUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 上传备件材料
 * Created by hyp1202 on 2018/7/16.
 */
@Controller
@RequestMapping("/accFilter")
public class AccraditationFilterController {
    @Autowired
    private NodeNewtempletService nodeNewtempletService;
    @Autowired
    private NodeNewschedulesService nodeNewschedulesService;
    @Autowired
    private NodeNewFilterService nodeFileService;
    @Autowired
    private SupervisionTaskService supervisionTaskService;
    @Autowired
    private CoordinateService coordinateService;

    @ModelAttribute("headType")
    public String returnHeadType(){
        return "管理模块";
    }

    @RequestMapping("/go/list")
    public String listFilter( Model model,HttpServletRequest request){
        BnpUser bnpUser =  (BnpUser) WebUtils.getSessionAttribute(request,"user");
        if (ObjectUtils.isBlank(bnpUser)){
            return "/modules/login/login";
        }
        Map<Object,Object> map = new LinkedHashMap<Object,Object>();
        NodeNewtempletFilter filter = new NodeNewtempletFilter();
        filter.setResDept(bnpUser.getBranch());
        filter.setOperatorUser(bnpUser.getName());
        filter.setType("1");
        List<NodeNewtemplet> list = nodeNewtempletService.getNodeForAcc(filter);
        for (NodeNewtemplet nodeTemp:list) {
            List<NodeNewfile> nodeFileList =  nodeFileService.getFilesByNodeId(nodeTemp.getNodeId());
            if (nodeFileList.size() == 0){
                continue;
            }
            map.put(nodeTemp,nodeFileList);
        }

        model.addAttribute("map",map);
        model.addAttribute("leftType","上传备件材料");

        int myTaskNum = (int) WebUtils.getSessionAttribute(request, "myTaskNum");
        int quetionNum = (int) WebUtils.getSessionAttribute(request, "quetionNum");
        model.addAttribute("myTaskNum", myTaskNum);
        model.addAttribute("quetionNum", quetionNum);

        int myTackTaskNum = (int) WebUtils.getSessionAttribute(request, "myTackTaskNum");
        model.addAttribute("myTackTaskNum", myTackTaskNum);

        //待办任务个数
        int nodeCount = (int) WebUtils.getSessionAttribute(request, "nodeCount");
        model.addAttribute("nodeCount", nodeCount);

        return  "/modules/Accraditation/Accraditation_upload";
    }
}
